package org.ruanjj.designmodel.enumsingleton;

//懒汉式，按需创建
//双重校验锁
//还是无法阻止反序列化和反射方式创建对象
public class Singleton3 {
    private static volatile Singleton3 instance;


    //私有化构造函数，不允许其他类new关键字创建
    private Singleton3(){

    }

    public static Singleton3 getInstance(){
        System.out.println(Thread.currentThread().getName()+"come in...");
        if(instance == null){
            synchronized (Singleton3.class){
                if(instance == null){
                    System.out.println(Thread.currentThread().getName()+"building...");
                    instance = new Singleton3();
                }
            }
        }

        return instance;
    }
}
